import { getCurrentInstance,type  ComponentInternalInstance, type ComponentPublicInstance } from "vue";
import type {
	ToastApp,
	Toast,
	ShowModal,
	GoLogin,
	LayoutGoTo,
	RouteJump,
	BackFn,
	CopyFn,
	calculateFn,
	SelectDictLabel,
	FormatNumberToK
} from "@/common/globalProperties/type";
import type { TimeFormat } from "@/uni_modules/endless-ui/libs/utils/lodash/date";

export interface VueProxy {
	$toastApp: ToastApp;
	$toast: Toast;
	$showModal: ShowModal;
	$goLogin:GoLogin;
	$goTo: RouteJump;
	$layoutGoTo:LayoutGoTo;
	$goRedirectTo: RouteJump;
	$goReLaunch: RouteJump;
	$switchTab: RouteJump;
	$back: BackFn;
	$copy: CopyFn;
	$accMul: calculateFn;
	$accAdd: calculateFn;
	$accDiv: calculateFn;
	$timeFormat: TimeFormat;
	$selectDictLabel:SelectDictLabel;
	$fullLink:(url:string) => string
	$staticPath:(url:string) => string
	$getShareUrlScene:(scene:string) =>string
	$formatNumberToK:FormatNumberToK
	$t(t:string):string
	mpShareInit():void
	AppSkinVar:Record<string,string>
	AppSkin:{
		type: string
		primary: string
		gradientPrimary: string
	}
	$unitEn:string
	$isEnglishVersion:boolean
	$toastAndBack(msg:string,delta?:number):void
	
}
export type AppContext = ComponentPublicInstance & VueProxy

export const useCurrentInstance = () => {
	const { proxy } = <ComponentInternalInstance>getCurrentInstance();
	// 返回全局上下文，并将上下文断言为非空
	return proxy! as AppContext;
};
